package com.my.thread.pool;

import java.util.concurrent.Callable;

/**
 * Created by ZhongGang
 * at 2018/7/13 10:23
 */
public class CallableTask<V> implements Task<AsyncResult<V>> {
    private Callable<V> callable;
    private AsyncResult<V> asyncResult;

    public CallableTask(Callable<V> callable, AsyncResult<V> asyncResult) {
        this.callable = callable;
        this.asyncResult = asyncResult;
    }

    @Override
    public AsyncResult<V> execute() throws Exception {
        V result = this.callable.call();
        this.asyncResult.setCompleted(true);
        this.asyncResult.setResult(result);
        return this.asyncResult;
    }
}
